home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / SBSIMDMO / SBSIMDMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  11.9 KB  |  365 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include "filefunc.h"
  5. #include "graph.h"
  6. #include "drvrfuncs.h"
  7. #include "sbsimdmo.h"
  8.  
  9. WINDOW sbwin[2] = {{VIEWABLE | SELECTABLE, " Digital Voice Files ", {5, 7},
  10.                                      {33, 15}, 0, 0, {NULL, NULL, NULL, NULL}},
  11.                                      {VIEWABLE | SELECTABLE, " Music Files ", {43, 7},
  12.                                      {33, 15}, 0, 0, {NULL, NULL, NULL, NULL}}};
  13.  
  14. void main(void)
  15. {
  16.     DVRINFO ctvoice;
  17.     DVRINFO ctvdsk;
  18.     DVRINFO auxdrv;
  19.     DVRINFO sbfmdrv;
  20.     DVRINFO sbmidi;
  21.  
  22.     int current;
  23.     int stat;
  24.     int error;
  25.     int i;
  26.     unsigned newLvl;
  27.     char choice = 0;
  28.  
  29.     InitScreen();
  30.  
  31.     // locate SBSIM driver
  32.     if((SIMint = FindDvr("SBSIM", 0x103)) == 0)
  33.     {
  34.         DrawError("SBSIM driver not loaded");
  35.         DemoExit(EXIT_FAILURE);
  36.     }
  37.  
  38.     // Get driver information
  39.     GetDvrInfo(MemVoice, &ctvoice);
  40.     GetDvrInfo(DskVoice, &ctvdsk);
  41.     GetDvrInfo(FM, &sbfmdrv);
  42.     GetDvrInfo(Midi, &sbmidi);
  43.  
  44.     // CTVDSK driver loaded?
  45.     if(ctvdsk.status == MISSING)
  46.         sbwin[0].status &= ~SELECTABLE;
  47.  
  48.     // SBFMDRV and SBMIDI drivers loaded?
  49.     if((sbfmdrv.status == MISSING) && (sbmidi.status == MISSING))
  50.         sbwin[1].status &= ~SELECTABLE;
  51.  
  52.     // AUXDRV driver loaded?
  53.     if(GetDvrInfo(AuxDrv, &auxdrv) == MISSING)
  54.         mixer = OFF;
  55.     else
  56.     {
  57.         mixer = ON;
  58.         // get current volumes
  59.         GetVolume(VOICE, &sbwin[0].mixLvl);
  60.         sbwin[0].mixLvl &= 0xff;                                 // just use the right channel
  61.         GetVolume(SYNTH, &sbwin[1].mixLvl);
  62.         sbwin[1].mixLvl &= 0xff;                                 // just use the right channel
  63.     }
  64.  
  65.     // display driver information window
  66.     if(DrawDrvrInfo(4, 9, Version(), &ctvoice, &ctvdsk, &auxdrv, &sbfmdrv,
  67.                                     &sbmidi) == ERROR)
  68.         DrawError(memErr);
  69.  
  70.     // Get VOC, MID, and CMF file names
  71.     GetFiles(sbmidi.status, sbfmdrv.status);
  72.  
  73.     current = (sbwin[0].status & SELECTABLE)? 0 : 1;
  74.     // draw digital voice (VOC) window
  75.     DrawWindow(&sbwin[0], (current == 0)? HIGHLIGHT : NORMAL);
  76.     // draw music (MID/CMF) window
  77.     DrawWindow(&sbwin[1], ((current == 1) && (sbwin[1].status & SELECTABLE))?
  78.                          HIGHLIGHT : NORMAL);
  79.  
  80.     // error if no files are available
  81.     if(!(sbwin[0].status & SELECTABLE) && !(sbwin[1].status & SELECTABLE))
  82.     {
  83.         DrawError("No VOC, MID, or CMF files available in this directory.");
  84.         DemoExit(EXIT_FAILURE);
  85.     }
  86.  
  87.     do
  88.     {
  89.         while(!kbhit())
  90.         {
  91.             if(sbwin[0].status & SELECTABLE)
  92.                 if(sbwin[0].fileList.active != NULL)
  93.                 {
  94.                     // if VOC file playing, check for status STOPPED
  95.                     if((GetSndStat(DskVoice) == STOPPED) &&
  96.                          (sbwin[0].fileList.active->status != STOPPED))
  97.                     {
  98.                         // update display to reflect change
  99.                         sbwin[0].fileList.active->status = STOPPED;
  100.                         sbwin[0].fileList.active = NULL;
  101.                         DrawFileList(&sbwin[0], (current == 0)? HIGHLIGHT : NORMAL);
  102.                     }
  103.                 }
  104.             if(sbwin[1].status & SELECTABLE)
  105.                 if(sbwin[1].fileList.active != NULL)
  106.                     // if MID or CMF file is playing, check for status STOPPED
  107.                     if((GetSndStat(FindFileType(sbwin[1].fileList.active->filename))
  108.                         == STOPPED) && (sbwin[1].fileList.active->status != STOPPED))
  109.                     {
  110.                         // update display to reflect change
  111.                         sbwin[1].fileList.active->status = STOPPED;
  112.                         sbwin[1].fileList.active = NULL;
  113.                         DrawFileList(&sbwin[1], (current == 1)? HIGHLIGHT : NORMAL);
  114.                     }
  115.         }
  116.         // keyboard event processing
  117.         choice = getch();
  118.         switch(choice)
  119.         {
  120.             case TAB:
  121.                 // can we switch to other window?
  122.                 if(sbwin[current ^ 1].status & SELECTABLE)
  123.                 {
  124.                     // display windows switched
  125.                     DrawWindow(&sbwin[current], NORMAL);
  126.                     current ^= 1;
  127.                     DrawWindow(&sbwin[current], HIGHLIGHT);
  128.                 }
  129.                 break;
  130.  
  131.             case LEFT:
  132.                 if((mixer == ON) && (sbwin[current].mixLvl >= 8))
  133.                 {
  134.                     newLvl = sbwin[current].mixLvl - 8;
  135.                     SetVolume((current == 0)? VOICE : SYNTH, (newLvl << 8) + newLvl);
  136.                     DrawSlider(&sbwin[current], newLvl, HIGHLIGHT);
  137.                 }
  138.                 break;
  139.  
  140.             case RIGHT:
  141.                 if((mixer == ON) && (sbwin[current].mixLvl < 248))
  142.                 {
  143.                     newLvl = sbwin[current].mixLvl    + 8;
  144.                     SetVolume((current == 0)? VOICE : SYNTH, (newLvl << 8) + newLvl);
  145.                     DrawSlider(&sbwin[current], newLvl, HIGHLIGHT);
  146.                 }
  147.                 break;
  148.             case UP:
  149.                 if(sbwin[current].fileList.current != sbwin[current].fileList.start)
  150.                     sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
  151.                 else
  152.                     if(sbwin[current].fileList.start->prev != NULL)
  153.                     {
  154.                         sbwin[current].fileList.start = sbwin[current].fileList.start->prev;
  155.                         sbwin[current].fileList.stop = sbwin[current].fileList.stop->prev;
  156.                         sbwin[current].fileList.current = sbwin[current].fileList.start;
  157.                     }
  158.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  159.                 break;
  160.  
  161.             case DOWN:
  162.                 if(sbwin[current].fileList.current != sbwin[current].fileList.stop)
  163.                     sbwin[current].fileList.current = sbwin[current].fileList.current->next;
  164.                 else
  165.                     if(sbwin[current].fileList.stop->next != NULL)
  166.                     {
  167.                         sbwin[current].fileList.start = sbwin[current].fileList.start->next;
  168.                         sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
  169.                         sbwin[current].fileList.current = sbwin[current].fileList.stop;
  170.                     }
  171.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  172.                 break;
  173.  
  174.             case PGUP:
  175.                 for(i = 0; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1)))
  176.                         && (sbwin[current].fileList.start->prev != NULL); i++)
  177.                 {
  178.                     sbwin[current].fileList.start = sbwin[current].fileList.start->prev;
  179.                     sbwin[current].fileList.stop = sbwin[current].fileList.stop->prev;
  180.                     sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
  181.                 }
  182.                 for(; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
  183.                         (sbwin[current].fileList.current != sbwin[current].fileList.start); i++)
  184.                     sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
  185.  
  186.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  187.                 break;
  188.  
  189.             case PGDOWN:
  190.                 for(i = 0; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1)))
  191.                         && (sbwin[current].fileList.stop->next != NULL); i++)
  192.                 {
  193.                     sbwin[current].fileList.start = sbwin[current].fileList.start->next;
  194.                     sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
  195.                     sbwin[current].fileList.current = sbwin[current].fileList.current->next;
  196.                 }
  197.                 for(; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
  198.                         (sbwin[current].fileList.current != sbwin[current].fileList.stop); i++)
  199.                     sbwin[current].fileList.current = sbwin[current].fileList.current->next;
  200.  
  201.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  202.                 break;
  203.  
  204.             case HOME:
  205.                 sbwin[current].fileList.start = sbwin[current].fileList.head;
  206.                 sbwin[current].fileList.current = sbwin[current].fileList.head;
  207.                 sbwin[current].fileList.stop = sbwin[current].fileList.head;
  208.                 for(i = 1; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
  209.                 (sbwin[current].fileList.stop->next != NULL) ; i++)
  210.                     sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
  211.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  212.                 break;
  213.  
  214.             case END:
  215.                 while(sbwin[current].fileList.stop->next != NULL)
  216.                 {
  217.                     sbwin[current].fileList.start = sbwin[current].fileList.start->next;
  218.                     sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
  219.                 }
  220.                 sbwin[current].fileList.current = sbwin[current].fileList.stop;
  221.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  222.                 break;
  223.  
  224.             case ENTER:
  225.                 switch(sbwin[current].fileList.current->status)
  226.                 {
  227.                     case STOPPED:
  228.                         if(sbwin[current].fileList.active != NULL)
  229.                         {
  230.                             sbwin[current].fileList.active->status = STOPPED;
  231.                             StopSnd(FindFileType(sbwin[current].fileList.active->filename));
  232.                         }
  233.                         sbwin[current].fileList.current->status = PLAYING;
  234.                         sbwin[current].fileList.active = sbwin[current].fileList.current;
  235.                         error = StartSnd(FindFileType(sbwin[current].fileList.current->filename),
  236.                                                          sbwin[current].fileList.current->filename, NULL, NULL);
  237.                         if(error == SIMerr_NoErr)
  238.                         {
  239.                             error = PlaySnd(FindFileType(sbwin[current].fileList.current->filename));
  240.                             if(error == SIMerr_NoErr)
  241.                             {
  242.                                 sbwin[current].fileList.current->status = PLAYING;
  243.                                 sbwin[current].fileList.active = sbwin[current].fileList.current;
  244.                             }
  245.                             else
  246.                             {
  247.                                 DrawWindow(&sbwin[current], NORMAL);
  248.                                 DrawError(errorMsg[error]);
  249.                                 DrawWindow(&sbwin[current], HIGHLIGHT);
  250.                             }
  251.                         }
  252.                         else
  253.                         {
  254.                             DrawWindow(&sbwin[current], NORMAL);
  255.                             DrawError(errorMsg[error]);
  256.                             DrawWindow(&sbwin[current], HIGHLIGHT);
  257.                         }
  258.                         break;
  259.                     case PAUSED:
  260.                         sbwin[current].fileList.current->status = PLAYING;
  261.                         ResumeSnd(FindFileType(sbwin[current].fileList.current->filename));
  262.                         break;
  263.                     case PLAYING:
  264.                         sbwin[current].fileList.current->status = STOPPED;
  265.                         sbwin[current].fileList.active = NULL;
  266.                         StopSnd(FindFileType(sbwin[current].fileList.current->filename));
  267.                         break;
  268.                     }
  269.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  270.                 break;
  271.  
  272.             case SPACE:
  273.                 if(sbwin[current].fileList.active != NULL)
  274.                     if(sbwin[current].fileList.active->status == PLAYING)
  275.                     {
  276.                         sbwin[current].fileList.active->status = PAUSED;
  277.                         PauseSnd(FindFileType(sbwin[current].fileList.active->filename));
  278.                     }
  279.                     else
  280.                     {
  281.                         sbwin[current].fileList.active->status = PLAYING;
  282.                         ResumeSnd(FindFileType(sbwin[current].fileList.active->filename));
  283.                     }
  284.                 DrawFileList(&sbwin[current], HIGHLIGHT);
  285.                 break;
  286.  
  287.             case ESC:
  288.                 if(sbwin[0].status & SELECTABLE)
  289.                     if(sbwin[0].fileList.active != NULL)
  290.                         if(sbwin[0].fileList.active->status != STOPPED)
  291.                             StopSnd(FindFileType(sbwin[0].fileList.active->filename));
  292.                 if(sbwin[1].status & SELECTABLE)
  293.                     if(sbwin[1].fileList.active != NULL)
  294.                         if(sbwin[1].fileList.active->status != STOPPED)
  295.                             StopSnd(FindFileType(sbwin[1].fileList.active->filename));
  296.                 break;
  297.             case F1:
  298.                 // draw current window unhighlighted
  299.                 DrawWindow(&sbwin[current], NORMAL);
  300.                 // display driver information window
  301.                 if(DrawDrvrInfo(4, 9, Version(), &ctvoice, &ctvdsk, &auxdrv, &sbfmdrv,
  302.                                                 &sbmidi) == ERROR)
  303.                     DrawError(memErr);
  304.                 // draw current window highlighted
  305.                 DrawWindow(&sbwin[current], HIGHLIGHT);
  306.                 break;
  307.             default:
  308.                 break;
  309.         }
  310.     }
  311.     while(choice != ESC);
  312.     DemoExit(EXIT_SUCCESS);
  313. }
  314.  
  315. /*************************************************************************
  316.  * FUNCTION: GETFILES - creates VOC and MID/CMF filename structures.
  317.  *
  318.  * Inputs: midStat - SBMIDI driver availability status (LOADED or MISSING).
  319.  * Inputs: cmfStat - SBFMDRV driver availability status (LOADED or MISSING).
  320.  *
  321.  * Output: none
  322.  *************************************************************************/
  323. void GetFiles(int midStat, int cmfStat)
  324. {
  325.     int error;
  326.  
  327.     // get VOC file names in current directory
  328.     if((error = GetFileList(&sbwin[0].fileList.head, "*.voc")) == MEMERR)
  329.         {
  330.             DrawError(dirMemErr);
  331.             DemoExit(EXIT_FAILURE);
  332.         }
  333.     if(error != FILERR)
  334.         // sort VOC filelist and place start, stop, and current pointers
  335.         InitFileList(&sbwin[0].fileList, sbwin[0].size.y - ((mixer == ON)? 3 : 1));
  336.     else
  337.         sbwin[0].status = ~VIEWABLE & ~SELECTABLE;
  338.  
  339.     if((midStat == LOADED) || !(sbwin[1].status & SELECTABLE))
  340.         // get MID file names in current directory
  341.         if((error = GetFileList(&sbwin[1].fileList.head, "*.mid")) == MEMERR)
  342.             {
  343.                 DrawError(dirMemErr);
  344.                 DemoExit(EXIT_FAILURE);
  345.             }
  346.         else
  347.             if(error == FILERR)
  348.                 sbwin[1].status = ~VIEWABLE & ~SELECTABLE;
  349.  
  350.     if((cmfStat == LOADED) || !(sbwin[1].status & SELECTABLE))
  351.         // get CMF file names in current directory
  352.         if((error = GetFileList(&sbwin[1].fileList.head, "*.cmf")) == MEMERR)
  353.         {
  354.             DrawError(dirMemErr);
  355.             DemoExit(EXIT_FAILURE);
  356.         }
  357.  
  358.     if((error != FILERR) || (sbwin[1].status & VIEWABLE))
  359.     {
  360.         // sort MID/CMF filelist and place start, stop, and current pointers
  361.         InitFileList(&sbwin[1].fileList, sbwin[1].size.y - ((mixer == ON)? 3 : 1));
  362.         sbwin[1].status = VIEWABLE | SELECTABLE;
  363.     }
  364. }
  365.